<?php

/**
 * Explorer default
 *
 * @copyright  Copyright (c) 2010 Albireo Solutions
 * @package    Kernel
 */

namespace ApplicationsModule\ExplorerModule;

use WebtopModule\BasePresenter;
use Albireo\RPC\RemoteProcedure;

class FsPresenter extends BasePresenter {

    /**
     * @var Albireo\RPC\FileSystemApi
     */
    private $rpcManagement;

    public function startup() {
        parent::startup();
        $this->rpcManagement = new FileSystemApi($this->getUser());
        $this->view = "fs";
    }

    public function actionLoad($what) {
        $dataFile = $this->rpcManagement->load($what);
        if (is_string($dataFile->getData())) {
            $this->template->raw = $dataFile->getData();
        } elseif (is_array($dataFile->getData())) {
            $this->template->data = ExplorerModel::processDir($dataFile);
        } else {
            $this->template->data = array();
        }
    }

    public function actionSave($what, $data, $mimeType = null) {
        $this->rpcManagement->save($what, $data, $mimeType);
    }

    public function actionGetFileInfo($what) {
        $dataFile = $this->rpcManagement->getFileInfo($what);
        $this->template->data = ExplorerModel::processFileInfo($dataFile);
    }

    public function actionCopy($what, $where, $rewrite) {
        $this->rpcManagement->copy($what, $where, $rewrite);
    }

    public function actionMove($what, $where, $rewrite) {
        $this->rpcManagement->move($what, $where, $rewrite);
    }

    public function actionDelete($what) {
        $this->rpcManagement->delete($what);
    }

}